<?php
/*
 * 列表页
 * @arrange Sameal
 * @package ixdcw
 * @file    list.inc.php
 * @time    13-3-14 下午1:15
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE . '/' . MODULE_NAME . '/common.inc.php';
$catid  = isset($cid) ? intval($cid) : $catid;
$cid    = isset($catid) ? intval($catid) : $catid;
$page   = isset($page) ? intval($page) : 0;
$areaid = isset($aid) ? intval($aid) : $areaid;

$children  = Category::children(4, $catid);
$siblings  = Category::siblings(4, $catid);
$maincats  = array_merge($children,$siblings);
foreach($maincats as $k=>$v){
	$maincat[$v['catid']] = $v;
}
$areaFilter = Area::children($areaid);
if (!$areaFilter) {
	$areaFilter = Area::siblings($areaid);
}

$condition = ' a.userid = m.userid and a.status=3  ';
$count_condition = 'status=3 ';
if ($areaid) {
	$area = Area::get($areaid);
	$condition .= ' and a.areaid in ('.$area['arrchildid'].')';
	$count_condition .= ' and areaid in ('.$area['arrchildid'].')';
}
if ($catid) {
	$cat = Category::module('store', $catid);

	$arrChilds = explode(',',$cat['arrchildid']);
	$strLike = '';
	$countLike = '';
	foreach($arrChilds as $child) {
		$strLike .= 'a.catid like "%,'.$child.',%" or ';
		$countLike .= 'catid like "%,'.$child.',%" or ';
	}
	$strLike = rtrim($strLike,'or ');
	$countLike = rtrim($countLike,'or ');
	$countLike = rtrim($countLike,'or ');
	$condition .= ' and ('. $strLike.')';
	$count_condition .= ' and ('. $countLike.')';
}

$shopAreaid = Area::ip2cityid($DT_IP);
if (!$shopAreaid) $shopAreaid = Area::AREA_CHINA;
// 增加url自动生成
$buildBase     = array('catid', 'areaid', 'page');
$buildDrop     = 'page';

$total    = $db->count($table, $count_condition);

$do = new StoreModule($moduleid);

if ($total) {
	$lists=$do->getListByLogintime($condition,$count_condition);
}

include template('iframe', MODULE_NAME);